import type {
  ActionConfig,
  DataRecord,
  FormConfig,
  PageConfig,
  PaginationConfig,
  SearchFieldConfig,
  TableColumn,
} from './config.type'

/**
 * 完整的页面配置
 */
const config = {
  // 页面基本信息
  page: {
    title: '用户管理',
    description: '管理系统中的用户信息',
    permission: 'acl:user',
    targetNameField: 'username',
  } as PageConfig,

  // API接口配置
  api: {
    GET_URL: '/users/list',
    CREATE_URL: '/users/save',
    UPDATE_URL: '/users/update',
    DELETE_URL: '/users/remove',
    BATCH_DELETE_URL: '/users/batchRemove',
    ASSIGN_ROLE_URL: '/users/getAssign',
    DO_ASSIGN_ROLE_URL: '/users/doAssign',
    ROLE_DICT_URL: '/role/dictionary',
    RESET_PASSWORD_URL: '/users/resetPassword',
  },

  // 搜索配置
  search: {
    fields: [
      {
        prop: 'username',
        label: '用户名',
        type: 'input',
        placeholder: '请输入账号或者用户名',
        clearable: true,
      },
    ] as SearchFieldConfig[],
    showReset: true,
    searchButtonText: '搜索',
    resetButtonText: '重置',
  },

  // 表格列配置
  tableColumns: [
    {
      type: 'selection',
      label: '选择',
      width: 55,
      align: 'center',
    },
    {
      type: 'index',
      label: '序号',
      width: 80,
      align: 'center',
    },
    {
      prop: 'avatar',
      label: '头像',
      type: 'image',
      width: 80,
      align: 'center',
      imageConfig: {
        width: 40,
        height: 40,
        fit: 'cover',
        shape: 'circle',
      },
    },
    {
      prop: 'username',
      label: '账号',
      minWidth: 'auto',
      align: 'center',
      sortable: true,
    },
    {
      prop: 'nickName',
      label: '昵称',
      minWidth: 'auto',
      align: 'center',
      showOverflowTooltip: true,
    },
    {
      prop: 'status',
      label: '状态',
      type: 'tag',
      width: 'auto',
      align: 'center',
      tagConfig: {
        textMap: {
          ACTIVE: '正常',
          INACTIVE: '停用',
        },
        typeMap: {
          ACTIVE: 'success',
          INACTIVE: 'warning',
        },
      },
    },
    // {
    //   prop: 'organization.name',
    //   label: '组织',
    //   minWidth: 120,
    //   align: 'center',
    //   showOverflowTooltip: true,
    // },
    // {
    //   prop: 'post.name',
    //   label: '岗位',
    //   minWidth: 120,
    //   align: 'center',
    //   showOverflowTooltip: true,
    // },
    {
      prop: 'roles',
      label: '角色',
      minWidth: 'auto',
      align: 'center',
      showOverflowTooltip: true,
      slotName: 'roles',
    },
    {
      prop: 'sort',
      label: '排序',
      minWidth: 'auto',
      align: 'center',
      sortable: true,
    },
    // {
    //   prop: 'createdAt',
    //   label: '创建时间',
    //   type: 'date',
    //   width: 180,
    //   align: 'center',
    //   sortable: true,
    //   dateConfig: {
    //     format: 'YYYY-MM-DD HH:mm:ss',
    //   },
    // },
    // {
    //   prop: 'updatedAt',
    //   label: '更新时间',
    //   type: 'date',
    //   width: 180,
    //   align: 'center',
    //   sortable: true,
    //   dateConfig: {
    //     format: 'YYYY-MM-DD HH:mm:ss',
    //   },
    // },
    //  操作列在page.vue中统一配置
  ] as TableColumn<DataRecord>[],

  // 表单配置
  form: {
    fields: [
      {
        prop: 'username',
        label: '账号',
        type: 'input',
        placeholder: '请输入账号（昵称，密码均默认为输入账号，请及时修改）',
        required: true,
        maxlength: 50,
        showWordLimit: true,
      },
      {
        prop: 'status',
        label: '状态',
        type: 'radio',
        options: [
          { label: '正常', value: 'ACTIVE' },
          { label: '停用', value: 'INACTIVE' },
        ],
        defaultValue: 'ACTIVE',
      },
      {
        prop: 'sort',
        label: '排序',
        type: 'number',
        placeholder: '请输入排序',
        maxlength: 50,
        showWordLimit: true,
      },
    ],
    rules: {
      username: [
        { required: true, message: '请输入用户名', trigger: 'blur' },
        { min: 6, max: 50, message: '用户名长度在 6 到 50 个字符', trigger: 'blur' },
      ],
    },
    labelWidth: '100px',
    dialogWidth: '600px',
    addTitle: '新增用户',
    editTitle: '编辑用户',
  } as FormConfig,

  // 操作按钮配置
  actions: {
    add: {
      text: '新增用户',
      icon: 'Plus',
      permission: 'btn.User.add',
    },
    batchDelete: {
      text: '批量删除',
      icon: 'Delete',
      permission: 'btn.User.remove',
    },
  } as ActionConfig,

  // 分页配置
  pagination: {
    pageSizes: [10, 20, 50, 100],
    defaultPageSize: 10,
  } as PaginationConfig,

  // 消息配置
  messages: {
    loadSuccess: '用户获取成功',
    loadError: '用户获取失败',
    addSuccess: '用户添加成功！',
    addError: '用户添加失败',
    editSuccess: '用户修改成功！',
    editError: '用户修改失败',
    deleteSuccess: '删除成功',
    deleteError: '删除失败',
    batchDeleteSuccess: '批量删除成功',
    batchDeleteError: '批量删除失败',
    uploadSuccess: 'Logo上传成功',
    uploadError: 'Logo图片上传失败',
    selectDeleteItems: '请选择要删除的数据',
    deleteConfirm: '确定要删除这个用户吗？删除后无法恢复！',
    batchDeleteConfirm: '确定要删除选中的 {count} 个用户吗？删除后无法恢复！',
    assignRoleSuccess: '角色分配成功',
    assignRoleError: '角色分配失败',
    assignRoleConfirm: '确定要将选中的 {count} 个用户分配给角色 "{roleName}" 吗？',
    resetPasswordSuccess: '密码重置成功',
    resetPasswordError: '密码重置失败',
    resetPasswordConfirm: '重置后密码将变为账号，确定要重置吗？',
  },
}

export default config
